import {createAsyncThunk, createSlice} from "@reduxjs/toolkit";
import {reqGetCourseList} from "../../api/frontDesk/frontDeskApi";

//获取到课程列表基础信息
export const getCourseList = createAsyncThunk(
    'course/getCourseListStatus',
    async (state, action) => {
        const data = await reqGetCourseList()
        console.log(data)
        const {courseList} = data
        return courseList
    }
)


const courseSlice = createSlice({
    name: 'course',
    initialState: {
        courseList: []
    },
    reducers: {
        updateCourseList(state, action) {
            state.courseList = action.payload
        }
    },
    extraReducers: (builder) => {
        builder.addCase(getCourseList.fulfilled, (state, action) => {
            state.courseList = action.payload
        })
    }
})

export const {updateCourseList} = courseSlice.actions
export const {reducer: courseReducer} = courseSlice